<template>
  <div class="login">
    <!-- 卡片 -->
    <div class="login_box">
      <el-card class="box-card">
        <!-- 图片区 -->
        <div class="avatar_box">
          <img src="../../assets/2.jpg" />
        </div>
        <!-- 登录表单 -->
        <el-form
          :model="loginForm"
          ref="LoginFormRef"
          :rules="loginFormRules"
          label-width="0px"
          class="login_form"
        >
          <!-- 用户名 -->
          <el-form-item prop="username">
            <el-input
              v-model="loginForm.username"
              prefix-icon="iconfont icon-user"
            ></el-input>
          </el-form-item>
          <!-- 密码 -->
          <el-form-item prop="password">
            <el-input
              type="password"
              v-model="loginForm.password"
              prefix-icon="iconfont icon-3702mima"
              show-password
            >
            </el-input>
          </el-form-item>
          <!-- 按钮 -->
          <el-form-item class="btns">
            <el-button type="primary" @click="denglu">登录</el-button>
            <el-button type="info" @click="chongzhi">重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>
</template>

<script>
import router from "../../router";

export default {
  name: "",

  components: {},

  data() {
    return {
      loginForm: {
        username: "",
        password: "",
      },
      //表单验证规则
      loginFormRules: {
        username: [
          { required: true, message: "请输入登录名", trigger: "blur" },
          {
            min: 3,
            max: 10,
            message: "登录名长度在 3 到 10 个字符",
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 6,
            max: 15,
            message: "密码长度在 6 到 15 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },

  created() {},

  methods: {
    denglu() {
      if (
        this.loginForm.username == "admin" &&
        this.loginForm.password == "123456"
      ) {
        this.$message({
          message: "登录成功",
          type: "success",
        });
        // 将用户的token进行保存，例如用户的token为curry
        //保存token
        const token = "curry";
        window.localStorage.setItem("token", token);
        this.$router.push("/main");
      } else {
        this.$message.error("用户名或密码错误");
      }
    },
    chongzhi() {
      this.loginForm.username = "";
      this.loginForm.password = "";
    },
  },
};
</script>

<style scoped lang="less">
.login {
  height: 100%;
  background-image: url("../../assets/1.jpg");
  background-size: 100% 100%;
}

.login_box {
  width: 450px;
  height: 300px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);

  .avatar_box {
    height: 130px;
    width: 130px;
    border: 1px solid #eee;
    border-radius: 50%;
    padding: 3px;
    box-shadow: 0 0 10px #ddd;
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #fff;

    img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
      background-color: #eee;
    }
  }
}

.login_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
}

.btns {
  display: flex;
  justify-content: flex-end;
  margin-right: 30px;
}

.el-card {
  background-color: rgba(255, 255, 255, 0.1);
}

.el-input {
  width: 90%;
}
</style>